package kr.co.graviti.common.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import kr.co.graviti.common.util.CommonVariable;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class LoginCheckInterceptor extends HandlerInterceptorAdapter {
	
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		
		HttpSession session = request.getSession(false);
		
		if (session == null) {
			response.sendRedirect("/");
			return false;
		}
		
		String user_id = (String)session.getAttribute(CommonVariable.SESSION_ADMIN_ID);
				
		if (user_id == null) {
			response.sendRedirect("/");
			return false;
		} else {
			session.setMaxInactiveInterval(60*60*2);
			
			return true;
		}
	}
}
